package com.xh.shuati.ai.rag;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pgvector.PgVectorEmbeddingStore;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 向量数据库配置类
 */
@Configuration
public class PgVectorStoreConfig {

    @Value("${spring.datasource.pgvector.host}")
    private String host;

    //使用PostgreSQL数据库
    @Value("${spring.datasource.pgvector.username}")
    private String userAccount;

    @Value("${spring.datasource.pgvector.password}")
    private String userPassword;


    //使用PostgreSQL数据库
    @Bean
    public EmbeddingStore<TextSegment> myEmbeddingStore(){
        return PgVectorEmbeddingStore.builder()
                .host(host)
                .port(5432)
                .database("hong_ai_agent")
                .user(userAccount)
                .password(userPassword)
                .table("embeddings")
                .dimension(1536)
                .build();
    }
}
